/* xx36.14.1cim.p - Gen CIM for importing Batch ID (from eb2.1 to 2015EE)
   Created By: Hayden (2015EE) 2016-06-13
   
   Purpose: Generate CIM for 2015EE importing Batch ID base on eb2.1
   Runtime: eb2.1
   Cimload: 2015EE
   
   Upgrade Step:
     1. run program in eb2.1 generate *.cim files
     2. ftp *.cim files to 2015EE
     3. doing cimload in each domain by cim file prefix
*/

{mfdtitle.i}
def var DOMAIN_PRC as char init 'PRC'.
def var DOMAIN_HK  as char init 'HK' .

def var outname     as char format 'x(12)' init '36.14.1-bc' label 'Out File'.
def var outfile_prc as char format 'x(20)'.
def var outfile_hk  as char format 'x(20)'.

outfile_prc = DOMAIN_PRC + '-' + outname + '.cim'.
outfile_hk  = DOMAIN_HK  + '-' + outname + '.cim'.

repeat:
  disp 'Generate CIM for 2015EE importing Batch ID base on eb2.1' skip
       'Runtime: eb2.1' skip
       'Cimload: 2015EE' skip(1)
       'Upgrade Step:' skip
       '  1. run program in eb2.1 generate *.cim files' skip
       '  2. ftp *.cim files to 2015EE' skip
       '  3. doing cimload in each domain by cim file prefix' skip(1)
       outname colon 14 '.cim' space(2) outfile_prc no-label view-as text
                               space(2) outfile_hk  no-label view-as text skip
  with frame a width 80 side-label.
  
  prompt-for outname with frame a editing:
    if frame-field = 'outname' then do:
      if input outname <> '' then do:
        disp DOMAIN_PRC + '-' + input outname + '.cim' @ outfile_prc with frame a.
        disp DOMAIN_HK  + '-' + input outname + '.cim' @ outfile_hk  with frame a.
      end.
      else do:
        disp '' @ outfile_prc with frame a.
        disp '' @ outfile_hk  with frame a.
      end.
    end.
    status input.
    readkey.
    apply lastkey.
  end.
  
  outname = input outname.
  
  if outname = '' then do:
    message 'Error: Please enter all Filenames'.
    next.
  end.
  
  outfile_prc = DOMAIN_PRC + '-' + outname + '.cim'.
  outfile_hk  = DOMAIN_HK  + '-' + outname + '.cim'.
  
  /* generate cim for PRC */
  os-delete value(outfile_prc).
  output to value(outfile_prc).  
  for each bc_mstr where bc_domain = global_domain
                     and bc_perm
                     no-lock:
    put '@@batchload mgbcmt.p' skip.
    put unformatted '"' bc_batch '"' skip.
    put unformatted '"' bc_perm '" ' bc_priority skip.
    put '@@end' skip.
  end.  
  output close.
  
  /* generate cim for HK */
  os-copy value(outfile_prc) value(outfile_hk).
  
  message 'Completed!'.
  
end.
